package com.jservice.web.supplier;

import com.jservice.framework.spring.SpringContextUtil;
import com.jservice.framework.utils.EncryptUtils;
import com.jservice.framework.utils.StringUtils;
import com.jservice.model.SysUser;
import com.jservice.web.base.JBaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * SupplierService
 *
 * @Author cwledit
 * @DATE 2017/7/13.
 */
@Service("supplierService")
@Transactional(readOnly = true)
public class SupplierService extends JBaseService {

    public static SupplierService me() {
        return SpringContextUtil.getBean("supplierService");
    }

    @Transactional
    public boolean update(SysUser user) {
        if (user == null){
            return false;
        }
        user.setModifyDate(new Date());
        if(StringUtils.isNotBlank(user.getPassword())){
            user.setPassword(EncryptUtils.encryptPassword(user.getPassword(),user.getLoginName().substring(0,3)));
        }else{
            user.remove("password");
        }
        if (user.update()){
            return true;
        }else{
            return false;
        }

    }

}
